package com.wn.controller;

import com.common.entity.Coupon;
import com.common.entity.Order;
import com.common.entity.PageParam;
import com.common.entity.Rsp;
import com.github.pagehelper.PageInfo;
import com.wn.service.CouponService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class CouponController {

    @Autowired
    private CouponService couponService;
    /**
     * @ClassName
     * @Description : 分页查询优惠券信息
     * @param: pageParam
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @PostMapping("searchSomeByPageCoupon")
    @ApiOperation("分页查询优惠券信息")
    public Rsp searchSomeByPageCoupon(@RequestBody PageParam<Coupon> coupon,
                                     @RequestHeader("token") String token){
        PageInfo<Coupon> pg = couponService.searchSomeByPage(coupon);
        return Rsp.success(pg);
    }

    /**
     * @ClassName
     * @Description :根据id查询优惠券
     * @param : id
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @GetMapping("getOneByIdCoupon/{id}")
    @ApiOperation("根据id查询优惠券")
    public Rsp getOneByIdCoupon(@PathVariable String id,
                               @RequestHeader("token") String token){

        Coupon oneById = couponService.getOneById(id);
        return Rsp.success(oneById);
    }

    /**
     * @ClassName
     * @Description : addOne添加优惠券
     * @param:
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @PutMapping("addOneCoupon")
    @ApiOperation("添加优惠券")
    public Rsp addOneCoupon(@RequestBody Coupon coupon,
                           @RequestHeader("token") String token){
        return couponService.addOne(coupon);
    }


    /**
     * @ClassName
     * @Description : update修改订单
     * @param :
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @PostMapping("updateCoupon")
    @ApiOperation("修改订单")
    public Rsp updateCoupon(@RequestBody Coupon coupon,
                           @RequestHeader("token") String token){
        return couponService.update(coupon);
    }


    /**
     * @ClassName
     * @Description : deleteLogical逻辑删除优惠券
     * @param :
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @PostMapping("deleteLogicalCoupon")
    @ApiOperation("逻辑删除优惠券")
    public Rsp deleteLogicalCoupon(@RequestBody Coupon coupon,
                                  @RequestHeader("token") String token){
        return couponService.deleteLogical(coupon);
    }


}
